package com.karst.essentials.chapter06.galaxyExample
{
	import com.karst.essentials.chapter06.InteractionTemplate;
	
	import flash.events.Event;
	
	import org.aswing.AsWingManager;
	import org.papervision3d.view.BasicView;
	
	public class GalaxyExample extends BasicView
	{
		public function GalaxyExample()
		{
			super( 640, 480, true, true ) ;
			createView() ;
			startRendering() ;
		}
		
		private var glaxy : Galaxy = null ;
		private var player : Player = null ;
		private var handler : UserInputHandler = null ;
		private var ctrl : CameraController = null ;
		private function createView():void
		{
			if( glaxy == null )
				glaxy = new Galaxy() ;
			
			if( player == null )
				player = new Player() ;
			
			if( handler == null )
				handler = new UserInputHandler( AsWingManager.getStage() ) ;
			
			if( ctrl == null )
				ctrl = new CameraController( camera, player ) ;

			scene.addChild( glaxy ) ;
			scene.addChild( player ) ;
			camera.target = player ;
			camera.z = -1500 ;
			camera.y = 400 ;
		}
		
		override protected function onRenderTick(event:Event=null):void
		{
			super.onRenderTick( event ) ;
			if( player )
				player.update() ;
			if( glaxy )
				glaxy.update() ;
			if( ctrl )
				ctrl.update() ;
		}
	}
}